﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using MOCSoftware.Utilities.JpgMetaDataViewer.Model;
using MOCSoftware.Utilities.JpgMetaDataViewer.Viewmodel;

namespace MOCSoftware.Utilities.JpgMetaDataViewer.Utility
{
    internal static class Extensions
    {
        internal static MenuItemCollection ToMenuItemCollection(this IEnumerable<MenuItemViewModel> collection)
        {
            var result = new MenuItemCollection();

            result.AddRange(collection);

            return result;
        }

        public static string GetDescription(this Enum value)
        {
            FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
            var descriptionAttribute =
                Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute)) as DescriptionAttribute;
            return descriptionAttribute == null ? value.ToString() : descriptionAttribute.Description;
        }

    }
}
